package com.uphone.kingmall.utils;

import android.widget.EditText;

import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;

/**
 * Created by GSD on 2016/11/29 0029.
 * 判断手机号是否正确，支持大陆和香港
 */
public class PhoneFormatCheckUtils {
    public static boolean isPhoneLegal(String str) throws PatternSyntaxException {
//        return isChinaPhoneLegal(str) || isHKPhoneLegal(str);
        return str.length() == 11 && str.startsWith("1");
    }

    private static boolean isHKPhoneLegal(String str) {
        String regExp= "^(5|6|8|9)\\d{7}$";
        Pattern p= Pattern.compile(regExp);
        Matcher m=p.matcher(str);
        return m.matches();
    }

    private static boolean isChinaPhoneLegal(String str) {
//        ^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$
        //^((13[0-9])|(15[^4])|(18[0,2,3,5-9])|(17[0-8])|(147))\d{8}$
        String regExp="^1([358][0-9]|4[579]|66|7[0135678]|9[89])[0-9]{8}$";
        Pattern p= Pattern.compile(regExp);
        Matcher m=p.matcher(str);
        return m.matches();
    }
    public static boolean isEmail(String str){
        String regExp="^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+((\\.[a-zA-Z_-]{2,3}){1,2})$";
        Pattern p= Pattern.compile(regExp);
        Matcher m=p.matcher(str);
        return m.matches();
    }
    public static boolean isNull(EditText editText){
        if (editText.getText()==null||editText.getText().toString().trim().equals("")){
            return true;
        }else {
            return false;
        }
    }
}
